from os import system
from random import randint
from os import system

T = 10
run = open('run.sh', 'w')

for f_id in range(31, 51):
    pf = f'data/{f_id:03d}'
    f = open(pf + '.in', 'w')

    print(T, file=f)

    for _ in range(T):
        n = randint(6, 50)
        nn = n // 2
        m = randint(0, nn**2)
        print(n, m, file=f)

        G = [list('-' * n) for _ in range(n)]
        avialable = set([(i, j) for i in range(n) for j in range(n)])

        k = randint(m // 6, m // 6 * 5)
        for _ in range(k):
            x, y = randint(0, n - 1), randint(0, n - 1)
            while ((x, y) not in avialable):
                x, y = randint(0, n - 1), randint(0, n - 1)
            G[x][y] = 'w' if randint(0, 1) else 'b'
            avialable.remove((x, y))

        for i in range(n):
            print(''.join(G[i]), file=f)

        for _ in range(m):
            x, y = randint(0, n - 1), randint(0, n - 1)
            while ((x, y) not in avialable):
                x, y = randint(0, n - 1), randint(0, n - 1)
            avialable.remove((x, y))
            # G[x][y] = 'w' if i % 2 == 0 else 'b'
            print(x, y, file=f)

    cmd = './sol <' + pf + '.in' + ' >' + pf + '.out'
    print(cmd, file=run)

# system('./run.sh')
